Here is a snippit of code that is causing an exception when the show(box) method is called:
string AAA()[]
{
string x[] = {"1", "2", "3", "4", "5", "6"}
return x
}
DB box = create "Hello"
string items[]
items = AAA()
DBE mylist = list(box, "Choose:", 5, items)
show box
DB box = create "Hello"
string items[] = {"a", "b", "c"}
DBE mylist = list(box, "Choose:", 5, items)
show box
SystemAdmin - Fri Oct 02 10:34:58 EDT 2009 |
Re: Populate List DBE with string array from function? Curious, this works OK:
string AAA()[]
{
string x[] = {"1", "2", "3", "4", "5", "6"}
return x
}
string items[]
items = AAA()
int Size = sizeof(items)
int i
for (i=0; i<Size; i++)
{ print "\t" items[i]
}
print "\n"
|
Re: Populate List DBE with string array from function? llandale - Fri Oct 02 11:04:49 EDT 2009 Curious, this works OK:
string AAA()[]
{
string x[] = {"1", "2", "3", "4", "5", "6"}
return x
}
string items[]
items = AAA()
int Size = sizeof(items)
int i
for (i=0; i<Size; i++)
{ print "\t" items[i]
}
print "\n"
You must be right - the array that is declared locally inside the function must be returned by reference - instead of a copy being returned. That doesn't completely explain why you can print the contents after the call returns but cannot use it in the list, except that it must still be sitting on the stack, unaltered for a short while after the return. Using this I tried to create the list using a dynamic array instead, but of course the create list call will not accept dynamic arrays. It looks like I will also have to resort to your hokey approach. lol! I will leave this question open for a little while to see if anyone else has any insight into this issue, and I'll posit this question as well: Would you consider this returning-the-array-by-reference behavior to be a bug in DXL? I would, as it makes returning arrays from functions valueless, and is certainly not the behavior I would expect. |
Re: Populate List DBE with string array from function? SystemAdmin - Fri Oct 02 11:51:15 EDT 2009 I notice we get similar diagnostic errors when you indeed pass a vector to a function as a parameter, using the &, expecting it to get modified. Don't use it and it works. Yup, looks like a bug to me. Tried various forms of 'addr_', but not clever enough to make it work.
|
Re: Populate List DBE with string array from function? Would this be a solution that would work for your situation?
DBE AAA(DB box)
{
string x[] = {"1","2"}
DBE d = list(box,"choose",sizeof(x),x)
return d
}
DB box = create "Hello"
DBE mylist = AAA(box)
show box
|
Re: Populate List DBE with string array from function? Doug.Zawacki - Mon Oct 05 13:48:19 EDT 2009 Would this be a solution that would work for your situation?
DBE AAA(DB box)
{
string x[] = {"1","2"}
DBE d = list(box,"choose",sizeof(x),x)
return d
}
DB box = create "Hello"
DBE mylist = AAA(box)
show box
As memtioned in that other thread, the issue seems to have been resolved sometime before Doors 8.3 |